Generate sequential numbers
Before you start
|
Why would I use a sequential number? Common uses include
|
Overview |
Step 1. Create a field for the sequential number within your template
- This can be any appropriate Item type for server-sequential numbers but must be a calculated value Item type for device-sequential numbers. For server-sequential numbers, select any appropriate numerical or text Item Type. For device-sequential numbers, select Calculated Value (5th down on the right).
Step 2. Set up an action to update your sequential number (server-side only)
- A template action needs to be set up for an appropriate report status.
- Click 'Add Action' at the appropriate report status of the template's lifecycle. This is likely to be 'When a report is received from a device (Incomplete or complete)' for creating a job number on an ad-hoc job (ie triggered onsite rather than from the office) but can be on any available action.
- Select 'Set a value for an item within the document' (4th down in the middle).
- Enter a meaningful description and the unique name applied to the template item in Step 1. 'Value to set' is where you will set up your sequential number (see Step 4). 'Conditions' and 'Post-action processing' tabs are not necessary for this task - see Template Action - Set a value for an item within the document if you wish investigate further.
Step 3. Enter a variable to construct a sequential number.
- The format $seq:[sequence name]:[starting number]:[increment] is used in a Calculated Field (for a device-side number) or in a Template Action (for a server-side number).
- This example tells magic5 to “use the sequence of numbers that we’re calling ‘DeviceSeqNo', start at 1000 and add on 1 on every time”.
- The sequence name is used to allow independent sequences of numbers to exist, such as Order numbers, PO numbers, within a single template.
- On the device the user will be asked to confirm that this is the first in a sequence when a sequence is started - this prevents a sequence from accidentally starting from scratch and thereby re-using previously allocated numbers.
- The sequence number on a device calculation is local to that device, so may be duplicated across devices - ie the number 10002 might occur several times. If this is a problem you may wish to use something like a username to give a unique value:
$user-$seq:Order:1000:1
which would result in, for instance, Fred-1000, Fred-1001 on one device and Bob-1000, Bob-1001 on another. -
In a server-based sequence the values will be unique because they are stored and allocated centrally. Usernames, and other report processing variables can be used, but the syntax is slightly different (eg %USER%-%$seq:sheetno:1000:1% to display Bob-1001 as above).
A sequence name can be shared between forms.
-
Update mode
Update mode determines how magic5 will behave when updating the attribute. The drop-down box contains the following options:
- Overwrite existing value – takes the value entered above and replaces the existing value. This is useful for recording date of most recent visit.
- Append to existing value – adds the new value onto whatever was there before. A full history of visit dates might be held in a string of data.
- Append to existing value with date/time heading – as above, the new value is added to the string of existing data but with the current date/time as well
- Create value only, don't overwrite – will never overwrite/update so it will only be created once as a new value. This is useful for recording the date of a first visit or assigning a job number to a job that may take some time to complete.
Example 1. Sales Order Number
- Follow Step 1 until you see the 'Add Item' menu.
- Select a Text item type from the top left of the menu.
- Enter something meaningful under Question, such as 'Order Number', and make sure that the Mandatory box is unticked. The other fields are irrelevant as the software will fill in the data.
- In the Advanced tab of the Text item enter a Unique name that reflects what the Text Item is to be used for, such as 'autogenOrderNo'. Make a note of this for later and save
- In the template screen, scroll to 'Actions to take' (this may be above or below the documents, pages, etc) and find the status 'When a report is received from the device (Incomplete or Complete)'. Click on the 'Add Action ...' button.
- Select 'Set a value for an item within the document' from the middle of the middle column in the Add Actions menu.
- Enter a meaningul description and the unique name of the Text item created above (we called it "autogenOrderNo" but you will have made a note of the name you used). Enter "$seq:Order:10000:1" in the Value to set prompt and select 'Create value only, don't overwrite' in the Update mode list (see Update mode for alternatives). Click Save and your Order Number is ready to use.
See Also